package models;

/**
 * class representing deck of cards,
 * methodes used to shuffle the cards
 * and draw a card from the deck
 */	
import java.util.*;

 
public class Deck{
	public ArrayList<Card> cards;
	Deck(){
        cards = new ArrayList<Card>();
        int index_1, index_2;
	    Random generator = new Random();
        Card temp;
	 
	        for (int a=0; a<=3; a++){		//creating a deck of 52 cards
	        	for (int b=0; b<=12; b++){	//13 cards in each of 4 colors
	              cards.add( new Card(a,b) );
	        	}
	        }
	        /* Shuffling method:
	         * randomly take 100 pairs of cards and switch them
	         */
	        for (int i=0; i<100; i++){		
            index_1 = generator.nextInt( cards.size() - 1 );
            index_2 = generator.nextInt( cards.size() - 1 );
 
            temp = cards.get( index_2 );
            cards.set( index_2 , cards.get( index_1 ) );
	            cards.set( index_1, temp );
	        }
	    }
	 
	void Shuffle(){		//Shuffle method itself
		 int index_1, index_2;
		 Random generator = new Random();
	     Card temp;
		 for (int i = 0; i < 100; i++){		
	            index_1 = generator.nextInt( cards.size() - 1 );
	            index_2 = generator.nextInt( cards.size() - 1 );
	 
	            temp = cards.get( index_2 );
	            cards.set( index_2 , cards.get( index_1 ) );
		            cards.set( index_1, temp );
		 }
	 }
	 
	public Card drawFromDeck(){	//to draw a card remove the first card from the top of ArrayList
	 	return cards.remove(0);
	}
	public void returnToDeck(Card c){
		int a = c.getSuit();
		int b = c.getRank();	
		cards.add(new Card(a,b));
	}
	
    public int getTotalCards(){
       return cards.size();   //get the total number of cards in deck, method used for tests
    }
    
}